import vbutton from '../components/vbutton'
export default {
  name: 'resindex',
  data() {
    return {
      restopic:"Register",
      resusername:"User name",
      respassward:"Passward",
      restel:"telphone",
      sendmes:"send",
      resstr:"please check your message",
      resbtn:"Submit",
      resmes: {username: '', userpas:'', usertel:''},
      err:{
        isuser:true
      }
    }
  },
  components:{
    vbutton
  },
  methods:{
    obuser:function (event) {
      var un=this.resmes.username;
      if(un=='') {
        this.err.isuser=false;
        this.resmes.username = "please enter username!!";
      }
    },
    ofuser:function (event) {
      var un=this.resmes.username;
      if(un=='please enter username!!') {
        this.err.isuser=true;
        this.resmes.username = "";
      }
    },
    resubmes:function() {
      var resname = this.resmes.username;
      var respas = this.resmes.userpas;
      var restel = this.resmes.usertel;
      var self=this;
      this.$http.post(
        "/api/addUser",
        {
          username: resname,
          userpas: respas,
          usertel: restel
        },
      )
        .then(function (res) {
          console.log("注册请求成功");
          console.log(res.data);
          if(res.data.status=='200'){
            alert("注册成功");
            //self.$router.push({path:'/loginindex'});
          }else {
            alert("注册失败")
          }
        })
        .catch(function (err) {
          console.log(err);
          alert("服务器错误");
        });
    }
  }
}
